/**
 * Created by tdzl2003 on 9/10/16.
 */

import React, { PropTypes } from 'react';
import FormModal from '../FormModal';
import {Form, Input} from 'antd';
import {login} from '../../logics/auth';

const fields = {
  account: {
    rules: [
      { required: true,  message: '请输入您的用户名' },
    ],
  },
  pwd: {
    rules: [
      { required: true, message: '请输入您的密码' },
    ],
  },
}

@Form.create()
export default class LoginModal extends React.Component {
  onReturn = ev => {
    this.refs.form.submit();
  };
  render() {
    const { getFieldProps } = this.props.form;
    return (
      <FormModal
        ref="form"
        title="登录"
        okTitle="登 录"
        onSubmit={login}
        {...this.props}
      >
        <Form.Item label="账号">
          <Input {...getFieldProps('account', fields.account)} onPressEnter={this.onReturn} />
        </Form.Item>
        <Form.Item label="密码">
          <Input {...getFieldProps('pwd', fields.pwd)} type="password" onPressEnter={this.onReturn} />
        </Form.Item>
      </FormModal>
    );
  }
}
